package com.adee.design.create.prototype;

// 原型模式： 实现Cloneable接口的clone方法，通过已有实例创建一个相同的实例
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Sheep s = new Sheep();
        Sheep s1 = s.clone();
        System.out.println(s == s1);
    }
}

class Sheep implements Cloneable {
    public Sheep() {
        System.out.println("创建一个Sheep实例");
    }
    @Override
    public Sheep clone() throws CloneNotSupportedException {
        System.out.println("克隆一个Sheep实例");
        return (Sheep)super.clone();
    }
}

